<?php
  class dashboard_main extends admin{
    function make_extra($buff,&$buff){

      $query = $this->query("SELECT * FROM ".KLEO_TABLE_PREFIX."blog, ".KLEO_TABLE_PREFIX."users  WHERE type = 1 AND aid = uid ORDER BY id DESC LIMIT 5");
      $i=0;
      if($this->num_rows($query) !== 0){
	$GLOBALS['has_posts'] = true;
	while($row = $this->fetch_array($query)){
	  $id = $row['id'];
	  $topics_query = $this->query("SELECT * FROM ".KLEO_TABLE_PREFIX."assoc, ".KLEO_TABLE_PREFIX."topics WHERE topicid = assoctopic AND assoctype = 1 AND associtem = $id LIMIT 1");
	  $topics_row = $this->fetch_array($topics_query);
	  $tags_query = $this->query("SELECT * FROM ".KLEO_TABLE_PREFIX."assoc, ".KLEO_TABLE_PREFIX."tags WHERE tagid = assoctopic AND assoctype = 4 AND associtem = $id");
	  $tags_row = $this->fetch_array($tags_query);
	  $GLOBALS['latest_posts'][$i] = $row;

	  if(empty($GLOBALS['latest_posts'][$i]['title'])){
		  $GLOBALS['latest_posts'][$i]['title'] = '('.L_NONE.')';
	  }

	  if(!empty($topics_row['tname'])){
	    $GLOBALS['latest_posts'][$i]['topic'] = $topics_row['tname'].'...';
	  } else {
	    $GLOBALS['latest_posts'][$i]['topic'] = '('.L_NONE.')';
	  }
	
	  if(!empty($tags_row['tagname'])){
	    $GLOBALS['latest_posts'][$i]['tag'] = $tags_row['tagname'].'...';
	  } else {
	    $GLOBALS['latest_posts'][$i]['tag'] = '('.L_NONE.')';
	  }
	  $i++;
	}
      }

      $query = $this->query("SELECT * FROM ".KLEO_TABLE_PREFIX."comments, ".KLEO_TABLE_PREFIX."users WHERE coaid = uid OR coaid = 0 GROUP BY coid DESC LIMIT 5");
      if($this->num_rows($query) !== 0){
	$GLOBALS['has_comments'] = true;
	$i=0;
	while($row = $this->fetch_array($query)){
	  $GLOBALS['latest_comments'][$i] = $row;
	  if(strlen($row['cotext']) > 64){
	    $GLOBALS['latest_comments'][$i]['cotext'] = substr($row['cotext'],0,48).'...';
	  }
	  if($row['coaid'] == 0){
	    $GLOBALS['latest_comments'][$i]['username'] = $row['cotitle'];
	  }
	  // Waiting moderation
	  if($row['costatus'] == 0){
	     $actions = '<a href="?module=admin&comment_action=approve&id='.$row['coid'].'">'.L_APPROVE.'</a> | <a href="?module=admin&comment_action=spam&id='.$row['coid'].'">'.L_SPAM.'</a> | <a href="?module=admin&file=edit_comment.tpl&id='.$row['coid'].'">'.L_EDIT.'</a>';
	  // Approved
	  } else if($row['costatus'] == 1){
	    $actions = '<a href="?module=admin&comment_action=spam&id='.$row['coid'].'">'.L_SPAM.'</a> | <a href="?module=admin&comment_action=delete&id='.$row['coid'].'" onclick="return confirm(\''.L_ASK_DELETE_COMMENT.'\');">'.L_DELETE.'</a> | <a href="?module=admin&file=edit_comment.tpl&id='.$row['coid'].'">'.L_EDIT.'</a>';
	  // Spam/Not approved
	  } else if($row['costatus'] == 2){
	    $actions = '<a href="?module=admin&comment_action=approve&id='.$row['coid'].'">'.L_NOT_SPAM.'</a> | <a href="?module=admin&comment_action=delete&id='.$row['coid'].'" onclick="return confirm(\''.L_ASK_DELETE_COMMENT.'\');">'.L_DELETE.'</a> | <a href="?module=admin&file=edit_comment.tpl&id='.$row['coid'].'">'.L_EDIT.'</a>';
	  }
	  $GLOBALS['latest_comments'][$i]['actions'] = $actions;
	  $i++;
	}
      }

    }

  }
?>
